package com.cnpinxi.interceptor;

import com.cnpinxi.controller.base.BaseController;
import com.cnpinxi.def.Constant;
import com.cnpinxi.domain.AdminUser;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Created by Baggio on 2017-3-24.
 */
public class OperateIntercept  extends BaseController implements HandlerInterceptor{
    @Override
    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
        System.out.println("==============================preHandle==============================>>>>>>>>>");
        this.showRequestParameters(httpServletRequest);
        System.out.println(o.toString());
        String requestUrl = httpServletRequest.getRequestURI().replace(httpServletRequest.getContextPath(), "");
        System.out.println(requestUrl);
        HttpSession session=httpServletRequest.getSession();
        System.out.println(session.getId());
        if ((AdminUser)session.getAttribute(Constant.SESSION_KEY_ADMDIN_USER_LOGIN)==null){
            System.out.println("还没有都能利用");
        }
        else{
            System.out.println("已经等了");

            System.out.println(((AdminUser)session.getAttribute(Constant.SESSION_KEY_ADMDIN_USER_LOGIN)).getTid());
            System.out.println(((AdminUser)session.getAttribute(Constant.SESSION_KEY_ADMDIN_USER_LOGIN)).getRealName());
            System.out.println(((AdminUser)session.getAttribute(Constant.SESSION_KEY_ADMDIN_USER_LOGIN)).getUserName());
        }
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
        System.out.println("==============================postHandle==============================>>>>>>>>>");
    }

    @Override
    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
        System.out.println("==============================afterCompletion==============================>>>>>>>>>");
    }
}
